/**********************************
	A Class that Allows me to 
	Load Configuration files
	to set things up

	By Julian Williams
	July 29, 2010
***********************************/

#include "cfg_reader.h"


cfg_reader::cfg_reader(string location, bool debug_mode)
{
	    ini = iniparser_load(location.c_str());

		if (ini==NULL)
		{
			cout << "Couldn't load configuration file, sorry :P \n";
		}

		debug = debug_mode;
		cout << boolalpha;
}//EoF


//Begin member Functions
string cfg_reader::Get_Info(string key, char * notFound)
{
	string t(iniparser_getstring(ini, key.c_str(), notFound));

	if(debug) 
	{ 
		cout << "cfg -> " << key.c_str() << " = " << t.c_str() << endl; 
	}

	return t;

}//EoF

int cfg_reader::Get_Info(string key, int notFound)
{
	int t = iniparser_getint(ini, key.c_str(), notFound);

	if(debug) 
	{ 
		cout << "cfg -> " << key.c_str() << " = " << t << endl; 
	}

	return t;
}//EoF

double cfg_reader::Get_Info(string key, double notFound)
{
	double t = iniparser_getdouble(ini, key.c_str(), notFound);

	if(debug) 
	{ 
		cout << "cfg -> " << key.c_str() << " = " << t << endl; 
	}

	return t;
}//EoF

bool cfg_reader::Get_Info(string key, bool notFound)
{
	bool t = iniparser_getboolean(ini, key.c_str(), notFound);

	if(debug) 
	{ 
		cout << "cfg -> " << key.c_str() << " = " << t << endl; 
	}

	return t;
}//EoF




cfg_reader::~cfg_reader(void)
{
	 iniparser_freedict(ini); //Free dictionary ini from memory
}
